/*
 * ContasAPagar.java
 *
 * Created on 30/06/2010, 14:57:33
 * Copyright Fm
 */
package Soligee.view;

import Soligee.controller.facade.sessionFacadeImplements.SessionFacadeAlterarImplements;
import Soligee.controller.facade.sessionFacadeImplements.SessionFacadeBuscarImplements;
import Soligee.controller.facade.sessionFacadeImplements.SessionFacadeCadastrarImplements;
import Soligee.decorador.PaginacaoListaDezEmDez;
import Soligee.model.vo.cadastros.ContaVO;
import Soligee.model.vo.cadastros.ParcelaNFEntradaVO;
import Soligee.model.vo.lancamentos.NFEntradaVO;
import com.icesoft.faces.component.ext.HtmlCommandButton;
import com.icesoft.faces.component.ext.HtmlDataTable;
import com.icesoft.faces.component.ext.HtmlInputText;
import com.icesoft.faces.component.ext.HtmlOutputLabel;
import com.icesoft.faces.component.ext.HtmlOutputText;
import com.icesoft.faces.component.ext.HtmlSelectOneMenu;
import com.icesoft.faces.component.ext.HtmlSelectOneRadio;
import com.icesoft.faces.component.jsfcl.data.DefaultSelectedData;
import com.icesoft.faces.component.jsfcl.data.DefaultSelectionItems;
import com.icesoft.faces.component.jsfcl.data.DefaultTableDataModel;
import com.icesoft.faces.component.jsfcl.data.SelectInputDateBean;
import com.icesoft.faces.component.panelpopup.PanelPopup;
import com.icesoft.faces.component.paneltabset.PanelTab;
import com.icesoft.faces.component.paneltabset.PanelTabSet;
import com.icesoft.faces.component.selectinputdate.SelectInputDate;
import com.sun.rave.faces.converter.SqlDateConverter;
import com.sun.rave.web.ui.appbase.AbstractPageBean;
import java.util.Date;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.FacesException;
import javax.faces.component.UISelectItems;
import javax.faces.component.html.HtmlCommandLink;
import javax.faces.event.ValueChangeEvent;
import javax.faces.model.SelectItem;



public class ContasAPagar extends AbstractPageBean {
    private int __placeholder;
    private List<ParcelaNFEntradaVO> listaDeParcelas;
    private List<ContaVO> listaDeConta;
    private static NFEntradaVO nfEntrada;
    private static ContaVO conta;
    private static ParcelaNFEntradaVO parcelaNFEntrada;
    private static int controle=0;
    private static int controlepopUp=0;
    private static PaginacaoListaDezEmDez paginacaoBusca;
    private SessionFacadeBuscarImplements facadeBusca = new SessionFacadeBuscarImplements();

    public static PaginacaoListaDezEmDez getPaginacaoBusca() {
        return paginacaoBusca;
    }

    public static void setPaginacaoBusca(PaginacaoListaDezEmDez paginacaoBusca) {
        ContasAPagar.paginacaoBusca = paginacaoBusca;
    }

    public List<ParcelaNFEntradaVO> getListaDeParcelas() {
        return listaDeParcelas;
    }

    public void setListaDeParcelas(List<ParcelaNFEntradaVO> listaDeParcelas) {
        this.listaDeParcelas = listaDeParcelas;
    }

    
   private void _init() throws Exception {
    }
   private HtmlSelectOneMenu tipoBusca = new HtmlSelectOneMenu();

   public HtmlSelectOneMenu getTipoBusca() {
      return tipoBusca;
   }

   public void setTipoBusca(HtmlSelectOneMenu hsom) {
      this.tipoBusca = hsom;
   }
   private DefaultSelectedData botaoSelecionadoTipoBusca2 = new DefaultSelectedData();

   public DefaultSelectedData getBotaoSelecionadoTipoBusca2() {
      return botaoSelecionadoTipoBusca2;
   }

   public void setBotaoSelecionadoTipoBusca2(DefaultSelectedData dsd) {
      this.botaoSelecionadoTipoBusca2 = dsd;
   }
   private DefaultSelectionItems botaoTipoBusca2 = new DefaultSelectionItems();

   public DefaultSelectionItems getBotaoTipoBusca2() {
      return botaoTipoBusca2;
   }

   public void setBotaoTipoBusca2(DefaultSelectionItems dsi) {
      this.botaoTipoBusca2 = dsi;
   }
    
   
    private DefaultSelectedData filtroSelecionado = new DefaultSelectedData();

    public DefaultSelectedData getFiltroSelecionado() {
        return filtroSelecionado;
    }

    public void setFiltroSelecionado(DefaultSelectedData dsd) {
        this.filtroSelecionado = dsd;
    }
    
    private DefaultTableDataModel dataTable1Model = new DefaultTableDataModel();

    public DefaultTableDataModel getDataTable1Model() {
        return dataTable1Model;
    }

    public void setDataTable1Model(DefaultTableDataModel dtdm) {
        this.dataTable1Model = dtdm;
    }
    private DefaultTableDataModel dataTable1Model1 = new DefaultTableDataModel();

    public DefaultTableDataModel getDataTable1Model1() {
        return dataTable1Model1;
    }

    public void setDataTable1Model1(DefaultTableDataModel dtdm) {
        this.dataTable1Model1 = dtdm;
    }
   private SelectInputDateBean selectInputDate1Bean = new SelectInputDateBean();

   public SelectInputDateBean getSelectInputDate1Bean() {
      return selectInputDate1Bean;
   }

   public void setSelectInputDate1Bean(SelectInputDateBean sidb) {
      this.selectInputDate1Bean = sidb;
   }
   private SelectInputDate dataEmissao = new SelectInputDate();

   public SelectInputDate getDataEmissao() {
      return dataEmissao;
   }

   public void setDataEmissao(SelectInputDate sid) {
      this.dataEmissao = sid;
   }
   private SelectInputDateBean selectInputDateBean6 = new SelectInputDateBean();

   public SelectInputDateBean getSelectInputDateBean6() {
      return selectInputDateBean6;
   }

   public void setSelectInputDateBean6(SelectInputDateBean sidb) {
      this.selectInputDateBean6 = sidb;
   }
   private SelectInputDate dataEntrada = new SelectInputDate();

   public SelectInputDate getDataEntrada() {
      return dataEntrada;
   }

   public void setDataEntrada(SelectInputDate sid) {
      this.dataEntrada = sid;
   }
   private PanelTab aba01 = new PanelTab();

   public PanelTab getAba01() {
      return aba01;
   }

   public void setAba01(PanelTab pt) {
      this.aba01 = pt;
   }
   private DefaultSelectedData selectOneRadio1Bean = new DefaultSelectedData();

   public DefaultSelectedData getSelectOneRadio1Bean() {
      return selectOneRadio1Bean;
   }

   public void setSelectOneRadio1Bean(DefaultSelectedData dsd) {
      this.selectOneRadio1Bean = dsd;
   }
   private DefaultSelectionItems selectOneRadio1DefaultItems = new DefaultSelectionItems();

   public DefaultSelectionItems getSelectOneRadio1DefaultItems() {
      return selectOneRadio1DefaultItems;
   }

   public void setSelectOneRadio1DefaultItems(DefaultSelectionItems dsi) {
      this.selectOneRadio1DefaultItems = dsi;
   }
   private PanelPopup panelPopup = new PanelPopup();

   public PanelPopup getPanelPopup() {
      return panelPopup;
   }

   public void setPanelPopup(PanelPopup pp) {
      this.panelPopup = pp;
   }
   private SelectInputDateBean selectInputDateBean8 = new SelectInputDateBean();

   public SelectInputDateBean getSelectInputDateBean8() {
      return selectInputDateBean8;
   }

   public void setSelectInputDateBean8(SelectInputDateBean sidb) {
      this.selectInputDateBean8 = sidb;
   }
    private UISelectItems selectOneRadio1selectItems = new UISelectItems();

    public UISelectItems getSelectOneRadio1selectItems() {
        return selectOneRadio1selectItems;
    }

    public void setSelectOneRadio1selectItems(UISelectItems uisi) {
        this.selectOneRadio1selectItems = uisi;
    }
    private HtmlSelectOneRadio buscaFinal = new HtmlSelectOneRadio();

    public HtmlSelectOneRadio getBuscaFinal() {
        return buscaFinal;
    }

    public void setBuscaFinal(HtmlSelectOneRadio hsor) {
        this.buscaFinal = hsor;
    }
    private HtmlDataTable tabelaNf = new HtmlDataTable();

    public HtmlDataTable getTabelaNf() {
        return tabelaNf;
    }

    public void setTabelaNf(HtmlDataTable hdt) {
        this.tabelaNf = hdt;
    }
    private HtmlDataTable tabelaContas = new HtmlDataTable();

    public HtmlDataTable getTabelaContas() {
        return tabelaContas;
    }

    public void setTabelaContas(HtmlDataTable hdt) {
        this.tabelaContas = hdt;
    }
    private PanelTab aba02 = new PanelTab();

    public PanelTab getAba02() {
        return aba02;
    }

    public void setAba02(PanelTab pt) {
        this.aba02 = pt;
    }
    private PanelTabSet painelBuscarContaAPagar = new PanelTabSet();

    public PanelTabSet getPainelBuscarContaAPagar() {
        return painelBuscarContaAPagar;
    }

    public void setPainelBuscarContaAPagar(PanelTabSet pts) {
        this.painelBuscarContaAPagar = pts;
    }
    
    private HtmlInputText campoCodigoNota = new HtmlInputText();

    public HtmlInputText getCampoCodigoNota() {
        return campoCodigoNota;
    }

    public void setCampoCodigoNota(HtmlInputText hit) {
        this.campoCodigoNota = hit;
    }
    private HtmlInputText campoNumeroNota = new HtmlInputText();

    public HtmlInputText getCampoNumeroNota() {
        return campoNumeroNota;
    }

    public void setCampoNumeroNota(HtmlInputText hit) {
        this.campoNumeroNota = hit;
    }
    private HtmlInputText campoFornecedor = new HtmlInputText();

    public HtmlInputText getCampoFornecedor() {
        return campoFornecedor;
    }

    public void setCampoFornecedor(HtmlInputText hit) {
        this.campoFornecedor = hit;
    }
        
    private HtmlInputText campoParcelas = new HtmlInputText();

    public HtmlInputText getCampoParcelas() {
        return campoParcelas;
    }

    public void setCampoParcelas(HtmlInputText hit) {
        this.campoParcelas = hit;
    }
    private HtmlInputText campoValorTotalNota1 = new HtmlInputText();

    public HtmlInputText getCampoValorTotalNota1() {
        return campoValorTotalNota1;
    }

    public void setCampoValorTotalNota1(HtmlInputText hit) {
        this.campoValorTotalNota1 = hit;
    }

    private HtmlInputText campoParcelaReferente = new HtmlInputText();

    public HtmlInputText getCampoParcelaReferente() {
        return campoParcelaReferente;
    }

    public void setCampoParcelaReferente(HtmlInputText hit) {
        this.campoParcelaReferente = hit;
    }
    private HtmlCommandLink linkAction2 = new HtmlCommandLink();

    public HtmlCommandLink getLinkAction2() {
        return linkAction2;
    }

    public void setLinkAction2(HtmlCommandLink hcl) {
        this.linkAction2 = hcl;
    }
    private HtmlCommandButton botaoPargarNf = new HtmlCommandButton();

    public HtmlCommandButton getBotaoPargarNf() {
        return botaoPargarNf;
    }

    public void setBotaoPargarNf(HtmlCommandButton hcb) {
        this.botaoPargarNf = hcb;
    }
    private HtmlInputText campoSituacaoNf = new HtmlInputText();

    public HtmlInputText getCampoSituacaoNf() {
        return campoSituacaoNf;
    }

    public void setCampoSituacaoNf(HtmlInputText hit) {
        this.campoSituacaoNf = hit;
    }
    private HtmlInputText campoValorTotalParcela = new HtmlInputText();

    public HtmlInputText getCampoValorTotalParcela() {
        return campoValorTotalParcela;
    }

    public void setCampoValorTotalParcela(HtmlInputText hit) {
        this.campoValorTotalParcela = hit;
    }
    private HtmlOutputText textoPopUp = new HtmlOutputText();

    public HtmlOutputText getTextoPopUp() {
        return textoPopUp;
    }

    public void setTextoPopUp(HtmlOutputText hot) {
        this.textoPopUp = hot;
    }
    private HtmlCommandButton btnPopUp1 = new HtmlCommandButton();

    public HtmlCommandButton getBtnPopUp1() {
        return btnPopUp1;
    }

    public void setBtnPopUp1(HtmlCommandButton hcb) {
        this.btnPopUp1 = hcb;
    }
    private HtmlCommandButton btnPopUp2 = new HtmlCommandButton();

    public HtmlCommandButton getBtnPopUp2() {
        return btnPopUp2;
    }

    public void setBtnPopUp2(HtmlCommandButton hcb) {
        this.btnPopUp2 = hcb;
    }
    private HtmlCommandButton panelLayoutLogo = new HtmlCommandButton();

    public HtmlCommandButton getPanelLayoutLogo() {
        return panelLayoutLogo;
    }

    public void setPanelLayoutLogo(HtmlCommandButton hcb) {
        this.panelLayoutLogo = hcb;
    }
    private HtmlCommandButton btn_voltar = new HtmlCommandButton();

    public HtmlCommandButton getBtn_voltar() {
        return btn_voltar;
    }

    public void setBtn_voltar(HtmlCommandButton hcb) {
        this.btn_voltar = hcb;
    }

    public List<ContaVO> getListaDeConta() {
        return listaDeConta;
    }

    public void setListaDeConta(List<ContaVO> listaDeParcelasConta) {
        this.listaDeConta = listaDeParcelasConta;
    }
    private HtmlOutputLabel codConta = new HtmlOutputLabel();

    public HtmlOutputLabel getCodConta() {
        return codConta;
    }

    public void setCodConta(HtmlOutputLabel hol) {
        this.codConta = hol;
    }
    private HtmlInputText campoCodigoConta = new HtmlInputText();

    public HtmlInputText getCampoCodigoConta() {
        return campoCodigoConta;
    }

    public void setCampoCodigoConta(HtmlInputText hit) {
        this.campoCodigoConta = hit;
    }
    private HtmlInputText campoDescricao = new HtmlInputText();

    public HtmlInputText getCampoDescricao() {
        return campoDescricao;
    }

    public void setCampoDescricao(HtmlInputText hit) {
        this.campoDescricao = hit;
    }
    private HtmlInputText campoValConta = new HtmlInputText();

    public HtmlInputText getCampoValConta() {
        return campoValConta;
    }

    public void setCampoValConta(HtmlInputText hit) {
        this.campoValConta = hit;
    }
    private SelectInputDate dataVencimento1 = new SelectInputDate();

    public SelectInputDate getDataVencimento1() {
        return dataVencimento1;
    }

    public void setDataVencimento1(SelectInputDate sid) {
        this.dataVencimento1 = sid;
    }
    private HtmlInputText campoSituacao = new HtmlInputText();

    public HtmlInputText getCampoSituacao() {
        return campoSituacao;
    }

    public void setCampoSituacao(HtmlInputText hit) {
        this.campoSituacao = hit;
    }
    private HtmlCommandButton botaoPagarConta = new HtmlCommandButton();

    public HtmlCommandButton getBotaoPagarConta() {
        return botaoPagarConta;
    }

    public void setBotaoPagarConta(HtmlCommandButton hcb) {
        this.botaoPagarConta = hcb;
    }
   
   private PanelPopup panelPopupConta = new PanelPopup();

   public PanelPopup getPanelPopupConta() {
      return panelPopupConta;
   }

   public void setPanelPopupConta(PanelPopup pp) {
      this.panelPopupConta = pp;
   }
    private HtmlCommandButton tabelaNfFooterFirstButton = new HtmlCommandButton();

    public HtmlCommandButton getTabelaNfFooterFirstButton() {
        return tabelaNfFooterFirstButton;
    }

    public void setTabelaNfFooterFirstButton(HtmlCommandButton hcb) {
        this.tabelaNfFooterFirstButton = hcb;
    }
    private HtmlCommandButton tabelaNfFooterPreviousButton = new HtmlCommandButton();

    public HtmlCommandButton getTabelaNfFooterPreviousButton() {
        return tabelaNfFooterPreviousButton;
    }

    public void setTabelaNfFooterPreviousButton(HtmlCommandButton hcb) {
        this.tabelaNfFooterPreviousButton = hcb;
    }
    private HtmlCommandButton tabelaNfFooterNextButton = new HtmlCommandButton();

    public HtmlCommandButton getTabelaNfFooterNextButton() {
        return tabelaNfFooterNextButton;
    }

    public void setTabelaNfFooterNextButton(HtmlCommandButton hcb) {
        this.tabelaNfFooterNextButton = hcb;
    }
    private HtmlCommandButton tabelaNfFooterLastButton = new HtmlCommandButton();

    public HtmlCommandButton getTabelaNfFooterLastButton() {
        return tabelaNfFooterLastButton;
    }

    public void setTabelaNfFooterLastButton(HtmlCommandButton hcb) {
        this.tabelaNfFooterLastButton = hcb;
    }
    private HtmlCommandButton tabelaContasFooterFirstButton = new HtmlCommandButton();

    public HtmlCommandButton getTabelaContasFooterFirstButton() {
        return tabelaContasFooterFirstButton;
    }

    public void setTabelaContasFooterFirstButton(HtmlCommandButton hcb) {
        this.tabelaContasFooterFirstButton = hcb;
    }
    private HtmlCommandButton tabelaContasFooterPreviousButton = new HtmlCommandButton();

    public HtmlCommandButton getTabelaContasFooterPreviousButton() {
        return tabelaContasFooterPreviousButton;
    }

    public void setTabelaContasFooterPreviousButton(HtmlCommandButton hcb) {
        this.tabelaContasFooterPreviousButton = hcb;
    }
    private HtmlCommandButton tabelaContasFooterNextButton = new HtmlCommandButton();

    public HtmlCommandButton getTabelaContasFooterNextButton() {
        return tabelaContasFooterNextButton;
    }

    public void setTabelaContasFooterNextButton(HtmlCommandButton hcb) {
        this.tabelaContasFooterNextButton = hcb;
    }
    private HtmlCommandButton tabelaContasFooterLastButton = new HtmlCommandButton();

    public HtmlCommandButton getTabelaContasFooterLastButton() {
        return tabelaContasFooterLastButton;
    }

    public void setTabelaContasFooterLastButton(HtmlCommandButton hcb) {
        this.tabelaContasFooterLastButton = hcb;
    }
    private SelectInputDateBean selectInputDateBean9 = new SelectInputDateBean();

    public SelectInputDateBean getSelectInputDateBean9() {
        return selectInputDateBean9;
    }

    public void setSelectInputDateBean9(SelectInputDateBean sidb) {
        this.selectInputDateBean9 = sidb;
    }

    private SelectInputDate dataVencimentoPopUp = new SelectInputDate();

    public SelectInputDate getDataVencimentoPopUp() {
        return dataVencimentoPopUp;
    }

    public void setDataVencimentoPopUp(SelectInputDate sid) {
        this.dataVencimentoPopUp = sid;
    }
    private HtmlInputText campoDescricaoConta = new HtmlInputText();

    public HtmlInputText getCampoDescricaoConta() {
        return campoDescricaoConta;
    }

    public void setCampoDescricaoConta(HtmlInputText hit) {
        this.campoDescricaoConta = hit;
    }
    private HtmlInputText campoValorConta = new HtmlInputText();

    public HtmlInputText getCampoValorConta() {
        return campoValorConta;
    }

    public void setCampoValorConta(HtmlInputText hit) {
        this.campoValorConta = hit;
    }
    private HtmlInputText campoCodigoConta1 = new HtmlInputText();

    public HtmlInputText getCampoCodigoConta1() {
        return campoCodigoConta1;
    }

    public void setCampoCodigoConta1(HtmlInputText hit) {
        this.campoCodigoConta1 = hit;
    }
    private HtmlCommandButton botaoNovaConta = new HtmlCommandButton();

    public HtmlCommandButton getBotaoNovaConta() {
        return botaoNovaConta;
    }

    public void setBotaoNovaConta(HtmlCommandButton hcb) {
        this.botaoNovaConta = hcb;
    }
    private SqlDateConverter sqlDateConverter1 = new SqlDateConverter();

    public SqlDateConverter getSqlDateConverter1() {
        return sqlDateConverter1;
    }

    public void setSqlDateConverter1(SqlDateConverter sdc) {
        this.sqlDateConverter1 = sdc;
    }
       
     public ContasAPagar() {
    }

    
    @Override
    public void init() {
        super.init();
        inicializaCampos();
        panelPopupConta.setRendered(false);
        try {
            _init();
        } catch (Exception e) {
            log("ContasAPagar Initialization Failure", e);
            throw e instanceof FacesException ? (FacesException) e: new FacesException(e);
        }
        
        
    }


    @Override
    public void preprocess() {
    }

    
    @Override
    public void prerender() {
    }

    
    @Override
    public void destroy() {
    }

    //coisas
  
   protected RequestBean1 getview$RequestBean1() {
      return (RequestBean1) getBean("view$RequestBean1");
   }

   
   protected ApplicationBean1 getview$ApplicationBean1() {
      return (ApplicationBean1) getBean("view$ApplicationBean1");
   }

  
   protected SessionBean1 getview$SessionBean1() {
      return (SessionBean1) getBean("view$SessionBean1");
   }

   public String panelLayoutLogo_action() {
       return "voltar";
   }

   public String btnPopUp1_action() {
      if(controle==0){
      parcelaNFEntrada.setSituacao(1);
      SessionFacadeAlterarImplements facadeAlterar = new SessionFacadeAlterarImplements();
        try {
            facadeAlterar.alterarParcelaNF(parcelaNFEntrada);
        } catch (Exception ex) {
            Logger.getLogger(ContasAPagar.class.getName()).log(Level.SEVERE, null, ex);
        }
      controlaPopup(true, "Parcela Paga com Sucesso!", false, true, "", "Ok");
      limparCamposNF();
      atualizaTabelaNF();
      botaoPargarNf.setRendered(false);
     
       }else if ((controle==1)&& (controlepopUp==0)){
               conta.setSituacao(1);
               SessionFacadeAlterarImplements facadeAlterar = new SessionFacadeAlterarImplements();
                try {
                    facadeAlterar.alterarConta(conta);
                } catch (Exception ex) {
                    Logger.getLogger(ContasAPagar.class.getName()).log(Level.SEVERE, null, ex);
                }
              controlaPopup(true, "Conta Paga com Sucesso!", false, true, "", "Ok");
              limparCamposConta();
              atualizaTabelaContas();
              
       }
       else if((controle==1)&&(controlepopUp==2)){
           Date dataVencimento = (Date)dataVencimentoPopUp.getValue();
           SessionFacadeCadastrarImplements cadastrar = new SessionFacadeCadastrarImplements();
           try {
           cadastrar.cadastrarConta(Integer.parseInt(campoCodigoConta1.getValue().toString()), campoDescricaoConta.getValue().toString(),
           Double.parseDouble(campoValorConta.getValue().toString()), dataVencimento, 0);
           } catch (Exception ex) {
            Logger.getLogger(ContasAPagar.class.getName()).log(Level.SEVERE, null, ex);
        }
            controlaPopup(true, "Conta Cadastrada com Sucesso!", false, true, "", "Ok");
            limpaCamposPopUpConta();
            atualizaTabelaContas();
       }
        return null;
   }

   public void inicializaCampos(){
        botaoPagarConta.setRendered(false);
        botaoPargarNf.setRendered(false);
        tabelaContas.setRendered(false);
        tabelaNf.setRendered(false);
        selectOneRadio1DefaultItems.clear();
        selectOneRadio1DefaultItems.add(new SelectItem(1,"Nota Fiscal"));
        selectOneRadio1DefaultItems.add(new SelectItem(2,"Contas"));
        panelPopup.setRendered(false);
        botaoPargarNf.setRendered(false);
        setarCamposNF(true);
        setarCamposConta(true);
   }

    public void buscaFinal_processValueChange(ValueChangeEvent vce) {
        if(Integer.parseInt(buscaFinal.getValue().toString())==1){
            botaoPargarNf.setRendered(false);
            controle=0;
            tabelaNf.setRendered(true);
            tabelaContas.setRendered(false);
            painelBuscarContaAPagar.setSelectedIndex(0);
            aba01.setDisabled(false);
            aba02.setDisabled(true);
           
            this.setListaDeParcelas(facadeBusca.buscarParcelaPendente("dataVencimento",ParcelaNFEntradaVO.class));
            dataTable1Model.setWrappedData(getListaDeParcelas());
            this.setPaginacaoBusca(new PaginacaoListaDezEmDez(this.getListaDeParcelas()));
            this.controlaPaginacaoNf(this.getListaDeParcelas().size());
        }
        else{
            botaoPagarConta.setRendered(false);
            controle=1;
            tabelaContas.setRendered(true);
            tabelaNf.setRendered(false);
            painelBuscarContaAPagar.setSelectedIndex(1);
            aba02.setDisabled(false);
            aba01.setDisabled(true);
            this.setListaDeConta(facadeBusca.buscarParcelaPendente("vencimento",ContaVO.class));
            dataTable1Model1.setWrappedData(getListaDeConta());
            this.setPaginacaoBusca(new PaginacaoListaDezEmDez(this.getListaDeConta()));
            this.controlaPaginacaoConta(this.getListaDeConta().size());
        }
    }

    
    public void setarCamposNF(boolean x){
        campoCodigoNota.setReadonly(x);
        campoFornecedor.setReadonly(x);
        campoNumeroNota.setReadonly(x);
        campoParcelas.setReadonly(x);
        campoParcelaReferente.setReadonly(x);
        campoValorTotalNota1.setReadonly(x);
        campoValorTotalParcela.setReadonly(x);
        dataEmissao.setDisabled(x);
        dataEntrada.setDisabled(x);
        campoSituacaoNf.setReadonly(x);
    }
    private void setarCamposConta(boolean x){
        campoCodigoConta.setReadonly(x);
        campoDescricao.setReadonly(x);
        campoValConta.setReadonly(x);
        dataVencimento1.setDisabled(x);
        campoSituacao.setReadonly(x);
    }
    private void limparCamposNF(){
        botaoPargarNf.setRendered(false);
        campoCodigoNota.resetValue();
        campoFornecedor.resetValue();
        campoNumeroNota.resetValue();
        campoParcelas.resetValue();
        campoParcelaReferente.resetValue();
        campoValorTotalNota1.resetValue();
        campoValorTotalParcela.resetValue();
        dataEmissao.resetValue();
        dataEntrada.resetValue();
        campoSituacaoNf.resetValue();
    }
    private void limparCamposConta(){
        botaoPagarConta.setRendered(false);
        campoCodigoConta.resetValue();
        campoDescricao.resetValue();
        campoValConta.resetValue();
        dataVencimento1.resetValue();
        campoSituacao.resetValue();
    }
    public void limpaCamposPopUpConta(){
        campoCodigoConta1.resetValue();
        campoDescricaoConta.resetValue();
        campoValorConta.resetValue();
        dataVencimentoPopUp.resetValue();

    }

    public String linkAction2_action() {
        botaoPargarNf.setRendered(true);
        parcelaNFEntrada = (ParcelaNFEntradaVO) tabelaNf.getRowData();
        nfEntrada=parcelaNFEntrada.getNfEntrada();
        campoCodigoNota.setValue(nfEntrada.getCodNFEntrada());
        campoFornecedor.setValue(nfEntrada.getFornecedor().getNome());
        campoNumeroNota.setValue(nfEntrada.getNumeroNFEntrada());
        campoParcelas.setValue(nfEntrada.getQtdadeParcela());
        campoParcelaReferente.setValue(parcelaNFEntrada.getNumParcela());
        campoValorTotalNota1.setValue(nfEntrada.getValorTotalNota());
        campoValorTotalParcela.setValue(parcelaNFEntrada.getValorParcela());
        dataEmissao.setValue(nfEntrada.getDataEmissao());
        dataEntrada.setValue(nfEntrada.getDataEntrada());

        if(parcelaNFEntrada.getSituacao()==0)
            campoSituacaoNf.setValue("Pendente");
        else if(parcelaNFEntrada.getSituacao()==1)
            campoSituacaoNf.setValue("Pago");
        else
            campoSituacaoNf.setValue("Vencido");
        
        return null;
    }

    public void controlaPopup(boolean renderedPopup,String textoPoup,boolean btn1Rendered, boolean btn2Rendered,
            String textobtn1, String textobtn2){
        panelPopup.setRendered(renderedPopup);
        textoPopUp.setValue(textoPoup);
        btnPopUp1.setValue(textobtn1);
        btnPopUp1.setRendered(btn1Rendered);
        btnPopUp2.setRendered(btn2Rendered);
        btnPopUp2.setValue(textobtn2);
    }

    public String botaoPargarNf_action() {
        controlaPopup(true, "Deseja Confirmar Pagamento?", true, true, "Sim", "Não");
        return null;
    }

    public String btnPopUp2_action() {
        panelPopup.setRendered(false);
        return null;
    }
    private void atualizaTabelaNF(){
            this.setListaDeParcelas(facadeBusca.buscarParcelaPendente("dataVencimento",ParcelaNFEntradaVO.class));
            dataTable1Model.setWrappedData(getListaDeParcelas());
            this.setPaginacaoBusca(new PaginacaoListaDezEmDez(this.getListaDeParcelas()));
            this.controlaPaginacaoNf(this.getListaDeParcelas().size());
    }
    private void atualizaTabelaContas(){
            this.setListaDeConta(facadeBusca.buscarParcelaPendente("vencimento",ContaVO.class));
            dataTable1Model1.setWrappedData(getListaDeConta());
            this.setPaginacaoBusca(new PaginacaoListaDezEmDez(this.getListaDeConta()));
            this.controlaPaginacaoConta(this.getListaDeConta().size());
    }

    public String btn_voltar_action() {
        //return null means stay on the same page
        return "voltar";
    }

    public String linkAction1_action() {
        botaoPagarConta.setRendered(true);
        conta = (ContaVO) tabelaContas.getRowData();
        campoCodigoConta.setValue(conta.getCodConta());
        campoDescricao.setValue(conta.getDescricao());
        campoValConta.setValue(conta.getValorConta());
        dataVencimento1.setValue(conta.getVencimento());
        if(conta.getSituacao()==0)
            campoSituacao.setValue("Pendente");
        else if(conta.getSituacao()==1)
            campoSituacao.setValue("Pago");
        else
            campoSituacao.setValue("Vencido");
        
        return null;
    }

    public String botaoPagarConta_action() {
        controlaPopup(true, "Deseja Confirmar Pagamento?", true, true, "Sim", "Não");
        controlepopUp=0;
        return null;
    }

   public String link_cancelarMarca_action() {
      //return null means stay on the same page
      return null;
   }

    public String tabelaNfFooterFirstButton_action() {
        dataTable1Model.setWrappedData(ContasAPagar.getPaginacaoBusca().firstPage());
        tabelaNfFooterFirstButton.setDisabled(true);
        tabelaNfFooterPreviousButton.setDisabled(true);
        if (ContasAPagar.getPaginacaoBusca().getTotalPaginas() > 1) {
            tabelaNfFooterNextButton.setDisabled(false);
            tabelaNfFooterLastButton.setDisabled(false);
        }
      return null;
    }

    public String tabelaNfFooterPreviousButton_action() {
        dataTable1Model.setWrappedData(ContasAPagar.getPaginacaoBusca().previousPage());
        if (ContasAPagar.getPaginacaoBusca().getNumeroDaPagina() == 1) {
            tabelaNfFooterNextButton.setDisabled(true);
            tabelaNfFooterFirstButton.setDisabled(true);
            tabelaNfFooterPreviousButton.setDisabled(true);
        }
        if (ContasAPagar.getPaginacaoBusca().getTotalPaginas() > 1) {
            tabelaNfFooterNextButton.setDisabled(false);
            tabelaNfFooterLastButton.setDisabled(false);
        }
        if (ContasAPagar.getPaginacaoBusca().getNumeroDaPagina() >= 2) {
            tabelaNfFooterFirstButton.setDisabled(false);
        }
        return null;
    }

    public String tabelaNfFooterNextButton_action() {
        dataTable1Model.setWrappedData(ContasAPagar.getPaginacaoBusca().nextPage());
        tabelaNfFooterPreviousButton.setDisabled(false);
        if (ContasAPagar.getPaginacaoBusca().getTotalPaginas() == ContasAPagar.getPaginacaoBusca().getNumeroDaPagina()) {
            tabelaNfFooterNextButton.setDisabled(true);
            tabelaNfFooterLastButton.setDisabled(true);
        }
        if (ContasAPagar.getPaginacaoBusca().getNumeroDaPagina() >= 2) {
            tabelaNfFooterFirstButton.setDisabled(false);
        }
         return null;
    }

    public String tabelaNfFooterLastButton_action() {
        dataTable1Model.setWrappedData(ContasAPagar.getPaginacaoBusca().lastPage());
        if (ContasAPagar.getPaginacaoBusca().getTotalPaginas() == ContasAPagar.getPaginacaoBusca().getNumeroDaPagina()) {
            tabelaNfFooterLastButton.setDisabled(true);
            tabelaNfFooterNextButton.setDisabled(true);
            tabelaNfFooterPreviousButton.setDisabled(false);
            tabelaNfFooterFirstButton.setDisabled(false);
        }
        if (ContasAPagar.getPaginacaoBusca().getNumeroDaPagina() >= 2) {
            tabelaNfFooterFirstButton.setDisabled(false);
        }
        return null;
    }

    /**************************************************************************/
    /*-------------------------Paginação Tabela Contas------------------------*/
    /**************************************************************************/
    public String tabelaContas_firstPageAction() 
        {
            dataTable1Model1.setWrappedData(ContasAPagar.getPaginacaoBusca().firstPage());
            tabelaContasFooterFirstButton.setDisabled(true);
            tabelaContasFooterPreviousButton.setDisabled(true);
            if (ContasAPagar.getPaginacaoBusca().getTotalPaginas() > 1) {
                tabelaContasFooterNextButton.setDisabled(false);
                tabelaContasFooterLastButton.setDisabled(false);
            }
            return null;
        }
            

    public String tabelaContas_previousPageAction(){
        dataTable1Model1.setWrappedData(ContasAPagar.getPaginacaoBusca().previousPage());
        if (ContasAPagar.getPaginacaoBusca().getNumeroDaPagina() == 1) {
            tabelaContasFooterNextButton.setDisabled(true);
            tabelaContasFooterFirstButton.setDisabled(true);
            tabelaContasFooterPreviousButton.setDisabled(true);
        }
        if (ContasAPagar.getPaginacaoBusca().getTotalPaginas() > 1) {
            tabelaContasFooterNextButton.setDisabled(false);
            tabelaContasFooterLastButton.setDisabled(false);
        }
        if (ContasAPagar.getPaginacaoBusca().getNumeroDaPagina() >= 2) {
            tabelaContasFooterFirstButton.setDisabled(false);
        }
        return null;
            }

    public String tabelaContas_nextPageAction(){
        dataTable1Model1.setWrappedData(ContasAPagar.getPaginacaoBusca().nextPage());
        tabelaContasFooterPreviousButton.setDisabled(false);
        if (ContasAPagar.getPaginacaoBusca().getTotalPaginas() == ContasAPagar.getPaginacaoBusca().getNumeroDaPagina()) {
            tabelaContasFooterNextButton.setDisabled(true);
            tabelaContasFooterLastButton.setDisabled(true);
        }
        if (ContasAPagar.getPaginacaoBusca().getNumeroDaPagina() >= 2) {
            tabelaContasFooterFirstButton.setDisabled(false);
        }
        return null;
        }

    public String tabelaContas_lastPageAction(){
        dataTable1Model1.setWrappedData(ContasAPagar.getPaginacaoBusca().lastPage());
        if (ContasAPagar.getPaginacaoBusca().getTotalPaginas() == ContasAPagar.getPaginacaoBusca().getNumeroDaPagina()) {
            tabelaContasFooterLastButton.setDisabled(true);
            tabelaContasFooterNextButton.setDisabled(true);
            tabelaContasFooterPreviousButton.setDisabled(false);
            tabelaContasFooterFirstButton.setDisabled(false);
        }
        if (ContasAPagar.getPaginacaoBusca().getNumeroDaPagina() >= 2) {
            tabelaContasFooterFirstButton.setDisabled(false);
        }
        return null;
    }

    public void controlaPaginacaoNf(int controlePaginas) {
      if (controlePaginas <= 10) {
         tabelaNfFooterFirstButton.setDisabled(true);
         tabelaNfFooterPreviousButton.setDisabled(true);
         tabelaNfFooterNextButton.setDisabled(true);
         tabelaNfFooterLastButton.setDisabled(true);
      }
      if (controlePaginas > 10) {
         tabelaNfFooterNextButton.setDisabled(false);
         tabelaNfFooterLastButton.setDisabled(false);
         tabelaNfFooterFirstButton.setDisabled(true);
         tabelaNfFooterPreviousButton.setDisabled(true);
      }
    }
    public void controlaPaginacaoConta(int controlePaginas) {
      if (controlePaginas <= 10) {
         tabelaContasFooterFirstButton.setDisabled(true);
         tabelaContasFooterPreviousButton.setDisabled(true);
         tabelaContasFooterNextButton.setDisabled(true);
         tabelaContasFooterLastButton.setDisabled(true);
      }
      if (controlePaginas > 10) {
         tabelaContasFooterNextButton.setDisabled(false);
         tabelaContasFooterLastButton.setDisabled(false);
         tabelaContasFooterFirstButton.setDisabled(true);
         tabelaContasFooterPreviousButton.setDisabled(true);
      }
    }

    public String link_cancelarConta_action() {
        panelPopupConta.setRendered(false);
        return null;
    }

    public String botaoNovaConta_action() {
        campoCodigoConta1.setValue(facadeBusca.totalDeRegistros(ContaVO.class)+1);
        panelPopupConta.setRendered(true);
        return null;
    }

    public String btn_cadastrarConta_action() {
        if (campoDescricaoConta.getValue().toString().equals("")||campoValorConta.getValue().toString().equals("")){
            controlaPopup(true, "Campos Obrigatórios faltando",false, true, "", "Ok");
            panelPopupConta.setRendered(false);
        }else {
        controlepopUp=2;
        System.out.println(controle);
        panelPopupConta.setRendered(false);
        controlaPopup(true, "Deseja Confirmar Cadastro ?", true, true, "Sim", "Não");
        }
        return null;
    }


   
}

